package xin.printk.android.module.plan;

import java.util.List;

import xin.printk.android.data.entity.Plan;
import xin.printk.android.utils.RequestCallback;

public class PlanPresenter implements PlanContract.Presenter {

    private PlanContract.View mView;

    public PlanPresenter(PlanContract.View view) {
        mView = view;
    }

    @Override
    public void refresh() {
        RequestCallback callback = new RequestCallback() {
            @Override
            public <T> void onSuccess(T t) {
                mView.notifyUpdate((List<Plan>) t);
            }

            @Override
            public void onFailure(String message) {
                mView.showError(message);
            }
        };
        mView.resetPage();
        if (mView.getState() == 0) {
            PlanModel.getUndonePlans(mView.getContext(), mView.getPageIndex(), callback);
        } else {
            PlanModel.getDonePlans(mView.getContext(), mView.getPageIndex(), callback);
        }
    }

    @Override
    public void loadMore() {
        RequestCallback callback = new RequestCallback() {
            @Override
            public <T> void onSuccess(T t) {
                mView.notifyMore((List<Plan>) t);
            }

            @Override
            public void onFailure(String message) {
                mView.showError(message);
            }
        };
        mView.morePage();
        if (mView.getState() == 0) {
            PlanModel.getUndonePlans(mView.getContext(), mView.getPageIndex(), callback);
        } else {
            PlanModel.getDonePlans(mView.getContext(), mView.getPageIndex(), callback);
        }
    }
}
